home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / IILS3P (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.2 KB  |  57 lines

  1. package java.awt;
  2.  
  3. import java.awt.peer.PopupMenuPeer;
  4.  
  5. public class PopupMenu extends Menu {
  6.    private static final String base = "popup";
  7.    static int nameCounter;
  8.    private static final long serialVersionUID = -4620452533522760060L;
  9.  
  10.    public PopupMenu() {
  11.       this("");
  12.    }
  13.  
  14.    public PopupMenu(String label) {
  15.       super(label);
  16.       super.name = "popup" + nameCounter++;
  17.    }
  18.  
  19.    public void addNotify() {
  20.       synchronized(((MenuComponent)this).getTreeLock()){}
  21.  
  22.       try {
  23.          if (super.peer == null) {
  24.             super.peer = Toolkit.getDefaultToolkit().createPopupMenu(this);
  25.          }
  26.  
  27.          int nitems = ((Menu)this).getItemCount();
  28.  
  29.          for(int i = 0; i < nitems; ++i) {
  30.             MenuItem mi = ((Menu)this).getItem(i);
  31.             mi.parent = this;
  32.             mi.addNotify();
  33.          }
  34.       } catch (Throwable var6) {
  35.          throw var6;
  36.       }
  37.  
  38.    }
  39.  
  40.    public void show(Component origin, int x, int y) {
  41.       Component p = (Component)super.parent;
  42.       if (p == null) {
  43.          throw new NullPointerException("parent is null");
  44.       } else if (p != origin && p instanceof Container && !((Container)p).isAncestorOf(origin)) {
  45.          throw new IllegalArgumentException("origin not in parent's hierarchy");
  46.       } else if (p.getPeer() != null && p.isShowing()) {
  47.          if (super.peer == null) {
  48.             this.addNotify();
  49.          }
  50.  
  51.          ((PopupMenuPeer)super.peer).show(new Event(origin, 0L, 501, x, y, 0, 0));
  52.       } else {
  53.          throw new RuntimeException("parent not showing on screen");
  54.       }
  55.    }
  56. }
  57.